package view;

import java.awt.Color;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import model.HPMP;
import model.Skill;
import controller.TestSkiller;
import javax.swing.ImageIcon;

@SuppressWarnings("serial")
public class SkillPanel extends JPanel implements Observer {
	private Skill skill;
	private JLabel lblSkillName;
	private JLabel lblBasicSkill;
	private JLabel lblSteps;
	private JLabel lblPowerUp;

	// private Color colorNostaleDarkBlue = new Color(0, 0, 34);
	private Color colorNostaleLightBlue = new Color(18, 26, 65);

	private TestSpinner spSpinner;
	private TestSpinner spinner;
	private JLabel lblSpPlusAll;
	private JLabel lblImage;
	private JLabel lblSpangriff;

	public SkillPanel(Skill skill, TestSkiller controller) {
		setForeground(Color.WHITE);
		this.skill = skill;
		setLayout(null);
		setBackground(colorNostaleLightBlue);

		lblImage = new JLabel("");
		lblImage.setIcon(new ImageIcon(SkillPanel.class.getResource(skill
				.getFileName())));
		lblImage.setBounds(0, 0, 38, 38);
		add(lblImage);

		lblSkillName = new JLabel(skill.getTitle());
		lblSkillName.setForeground(Color.WHITE);
		lblSkillName.setHorizontalAlignment(SwingConstants.CENTER);
		lblSkillName.setBounds(141, 14, 76, 14);
		add(lblSkillName);

		// change to label
		lblBasicSkill = new JLabel("BasicSkill");
		lblBasicSkill.setBounds(48, 11, 45, 20);
		lblBasicSkill.setForeground(Color.WHITE);
		lblBasicSkill.setHorizontalAlignment(SwingConstants.CENTER);
		add(lblBasicSkill);

		lblSteps = new JLabel();
		lblSteps.setHorizontalAlignment(SwingConstants.CENTER);
		lblSteps.setForeground(Color.WHITE);
		lblSteps.setBounds(103, 14, 28, 14);
		add(lblSteps);

		lblPowerUp = new JLabel();
		lblPowerUp.setHorizontalAlignment(SwingConstants.CENTER);
		lblPowerUp.setForeground(Color.WHITE);
		lblPowerUp.setBounds(227, 14, 45, 14);
		add(lblPowerUp);

		spSpinner = new TestSpinner(skill, true, 0, 17, controller);
		spSpinner.setBounds(480, 11, 45, 20);
		add(spSpinner);

		lblSpPlusAll = new JLabel("SPALL");
		lblSpPlusAll.setSize(20, 14);
		lblSpPlusAll.setLocation(420, 14);
		lblSpPlusAll.setHorizontalAlignment(SwingConstants.CENTER);
		lblSpPlusAll.setForeground(Color.WHITE);
		lblSpPlusAll.setBounds(535, 14, 20, 14);
		add(lblSpPlusAll);

		// lblSkillPlusSp to spinner
		spinner = new TestSpinner(skill, false, 0, 100, controller);
		spinner.addChangeListener(controller);
		spinner.setForeground(Color.WHITE);
		spinner.setBounds(304, 14, 45, 20);
		add(spinner);
		
		lblSpangriff = new JLabel(skill.getSPStat());
		lblSpangriff.setHorizontalAlignment(SwingConstants.TRAILING);
		lblSpangriff.setForeground(Color.WHITE);
		lblSpangriff.setBounds(355, 14, 115, 14);
		add(lblSpangriff);

		update(null, null);
	}

	public TestSpinner getSpinner() {
		return spinner;
	}

	public TestSpinner getSpSpinner() {
		return spSpinner;
	}

	@Override
	public void update(Observable arg0, Object arg1) {
		lblBasicSkill.setText("" + skill.getSkillValue());
		lblSteps.setText("" + skill.getSkillSteps());
		lblSpPlusAll.setText("" + (skill.getTotal() - skill.getSkillValue()));
		lblPowerUp.setText("" + skill.getPowerUp());
		if (skill instanceof HPMP)
			lblPowerUp.setText(lblPowerUp.getText() + " %");

	}

	public void resetSpinner() {
		System.out.println();
		spinner.setValue(skill.getTotal());	
		spSpinner.setValue(skill.getSpValue());
	}
	
	
	
	public Skill getSkill() {
		return skill;
	}
}
